home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / zmdm.zoo / util.c < prev    next >
C/C++ Source or Header  |  1991-04-27  |  6KB  |  262 lines

  1. /*
  2.  *     Utilities Module
  3.  *
  4.  *        Jwahar Bammi
  5.  *            usenet: mandrill!bammi@{decvax,sun}.UUCP
  6.  *            csnet:  bammi@mandrill.ces.CWRU.edu
  7.  *            arpa:   bammi@mandrill.ces.CWRU.edu
  8.  *            CompuServe: 71515,155
  9.  */
  10.  
  11.  
  12. #include "config.h"
  13. #include "zmdm.h"
  14.  
  15. #ifndef Vsync             /* Atari forgot these in osbind.h */
  16. #define Vsync()    xbios(37)
  17. #endif
  18.  
  19. #define GOTO(r,c)    EscSeq('Y');Bconout(2, r+040);Bconout(2, c+040)
  20.  
  21.      /* External Variables */
  22. #ifdef __GNUC__
  23. volatile long     pr_time   = 0L;  /* Present time      (200 Hz) */ 
  24. #else
  25. long     pr_time   = 0L;      /* Present time      (200 Hz) */ 
  26. #endif
  27.  
  28. #ifndef STANDALONE
  29. #ifndef REMOTE
  30. extern int  *aline_addr; /* Ptr to base of Aline variables */
  31. extern long *ms_ptr;    /* pointer to my screen memory aligned to a 256
  32.                byte boundary */
  33.  
  34. #ifndef OVERSCAN
  35.      /* Globals */
  36. static char *hs_ptr;   /* pointer to his screen memory */
  37. #else
  38. extern long *ms_log;
  39.   
  40.        /* Globals */
  41. static char *hs_phys;   /* pointer to his screen memory */
  42. static char *hs_log;
  43. #endif /* OVERSCAN */
  44. static int  x_saved, y_saved;    /* Saved cursor position */
  45. #endif
  46. #endif
  47.  
  48. static long *hz_200 =  (long *)0x000004ba; /* Yes the Hitch Hikers */
  49.                        /* Guide is wrong!! */
  50.  
  51. /*
  52.  * rd_time() - read the value of the systems 200 Hz counter
  53.  * must be called in Super Mode else you get
  54.  * what you deserve - MUSHROOMS!!
  55.  */
  56. void rd_time()
  57. {
  58.     pr_time = *hz_200;
  59. }
  60.  
  61. #ifndef STANDALONE
  62. /*
  63.  * my_screen() - Start using my screen memory
  64.  * for all output.
  65.  *
  66.  */
  67. void my_screen()
  68. {
  69. #ifndef REMOTE
  70.     /* The cursor position has been saved prior to calling this routine */
  71.     x_saved = aline_addr[-14];
  72.     y_saved = aline_addr[-13];
  73.  
  74. #ifndef OVERSCAN
  75.     /* save his screen memory pointer */
  76.     hs_ptr = (char *)Logbase();
  77.     
  78.     /* switch to my display memory */
  79.     Setscreen(ms_ptr, ms_ptr, -1);
  80. #else
  81.     /* save his screen memory pointer */
  82.     hs_phys= (char *)Physbase();
  83.     hs_log = (char *)Logbase();
  84.     
  85.     /* switch to my display memory */
  86.     Setscreen(ms_log, ms_ptr, -1);
  87. #endif /* OVERSCAN */
  88.     Vsync(); Vsync();
  89. #else
  90.     wr_modem("\r\n\n");
  91. #endif
  92. }
  93.  
  94.  
  95. void his_screen()
  96. {
  97. #ifndef REMOTE
  98.     /* switch to his Screen memory, wait for a Vblank, so
  99.      * that the Logical Loc == Physical Loc, then pop saved
  100.      * cursor */
  101. #ifndef OVERSCAN
  102.     Setscreen(hs_ptr, hs_ptr, -1);
  103. #else
  104.     Setscreen(hs_log, hs_phys, -1);
  105. #endif
  106.     Vsync();
  107.     Vsync();    /* starts happening at the last one */
  108.     GOTO(y_saved, x_saved);
  109. #else
  110.     wr_modem("\r\n\n");
  111. #endif
  112.     
  113. }
  114.  
  115. /*
  116.  * hit_key() - wait for the user to hit a key
  117.  * 
  118.  */
  119. void hit_key()
  120. {
  121. #ifndef REMOTE
  122.     Bconws("\r\n\033pHit Any Key To Continue .....\033q");
  123.     Bconin(2);
  124.     Bconws("\r\n");
  125. #else
  126.     wr_modem("\r\nHit Any Key To Continue .....");
  127.     Bconin(1);
  128.     wr_modem("\r\n");
  129. #endif
  130. }
  131. #endif /* STANDALONE */
  132.  
  133. /*
  134.  * find the size of a file given its name
  135.  */
  136. long filesize(name)
  137. register char *name;
  138. {
  139.     extern struct stat statbuf;
  140.     
  141.     if(Fsfirst(name,(int)(0x01 | 0x020)) != 0)
  142.     {
  143.         return 0L;
  144.         
  145.     }
  146.  
  147.     return statbuf.st_size;
  148. }
  149.  
  150.  
  151. /*
  152.  * Write a string to console
  153.  */
  154. void Bconws(s)
  155. register char *s;
  156. {
  157.     while(*s)
  158.         Bconout(2, *s++);
  159. }
  160.  
  161. #ifndef STANDALONE
  162. #ifndef REMOTE
  163. #ifndef __GNUC__
  164. #ifndef MANX
  165. #ifndef MWC
  166.  
  167. /* **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** */
  168. /*                                       */
  169. /*  ALCYON C dependant, this routine must return the base address of       */
  170. /*    of the linea variable block                       */
  171. /*                                       */
  172. /* **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** */
  173.  
  174. /*
  175.  * return the base address of the line A variables 
  176.  */
  177. int *aaddress()
  178. {
  179.     asm("dc.w $A000");    /* Line A trap - 0000 is init aline  */
  180.                 /* d0 and a0 now contain the address */
  181.                 /* so we can just return and the result
  182.                  * will be valid
  183.                  */
  184. }
  185.  
  186.  
  187. /*
  188.  *  Make hi rez screen bios handle 50 lines of 8x8 characters
  189.  *
  190.  * Adapted to C use from origonal asm posting
  191.  *
  192.  */
  193. void hi50()
  194. {
  195.     /* Switch to 50 lines display */
  196.  
  197.     asm(".dc.w    $a000");        /* get the important pointers */
  198.  
  199.     asm("move.l  04(a1),a1");    /* a1 -> 8x8 font header */
  200.  
  201.     asm("move.l  72(a1),-$0A(a0)");    /* v_off_ad <- 8x8 offset table addr */
  202.     asm("move.l  76(a1),-$16(a0)");    /* v_fnt_ad <- 8x8 font data addr */
  203.  
  204.     asm("move.w  #008,-$2E(a0)");    /* v_cel_ht <- 8    8x8 cell height */
  205.     asm("move.w  #049,-$2A(a0)");    /* v_cel_my <- 49   maximum cell "Y" */
  206.     asm("move.w  #640,-$28(a0)"); /* v_cel_wr <- 640  offset to cell Y+1 */
  207.  
  208. }
  209.    
  210. /*
  211.  * Make hi rez screen bios handle 25 lines of 8x16 characters
  212.  *
  213.  */
  214. void hi25()
  215. {
  216.     
  217.     /* Switch to 25 lines display */
  218.  
  219.  
  220.     asm(".dc.w    $a000");        /* get the important pointers */
  221.     
  222.     asm("move.l  08(a1),a1");    /* a1 -> 8x16 font header */
  223.  
  224.     asm("move.l  72(a1),-$0A(a0)");    /* v_off_ad <- 8x16 offset table addr */
  225.     asm("move.l  76(a1),-$16(a0)");    /* v_fnt_ad <- 8x16 font data addr */
  226.  
  227.     asm("move.w  #0016,-$2E(a0)");    /* v_cel_ht <- 16    8x16 cell height */
  228.     asm("move.w  #0024,-$2A(a0)");    /* v_cel_my <- 24    maximum cell "Y" */
  229.     asm("move.w  #1280,-$28(a0)");    /* v_cel_wr <- 1280  vertical byte offset */
  230. }
  231.  
  232. #else
  233.  
  234. /* **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** */
  235. /*                                       */
  236. /*     MWC  dependant, this routine must return the base address of       */
  237. /*    of the linea variable block                       */
  238. /*                                       */
  239. /* **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** **WARNING** */
  240. #include <linea.h>
  241. /*
  242.  * return the base address of the line A variables 
  243.  */
  244.  
  245. int *aaddress()
  246. {
  247.     linea0();    /* Init LineA - dumps returned values into la_init */
  248.     return (int *)(la_init.li_a0); /* Return address of Parameter Block */
  249. }
  250.  
  251.         /* Mark Williams C        */
  252.         /* See file hi5025.s       */
  253.         /* for functions hi50()    */
  254.         /* and hi25()           */
  255. #endif /* MWC */
  256. #endif /* MANX */
  257. #endif /* __GNUC__ */    /* see ghi5025 for Gnu version */
  258. #endif /* REMOTE */
  259. #endif /* STANDALONE */
  260.  
  261. /* -eof- */
  262.